package com.stone.business.gzrwd.action;

/**
 * <pre>
 * 运行工作系统查询
 * </pre>
 */

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.stone.business.gzrwd.pojo.TGzrwdRw_old;
import com.stone.business.gzrwd.service.ZbjlCommonService;
import com.stone.para.IConstant;
import com.stone.sys.pojo.TUser;
import com.stone.sys.service.DictionaryService;
import com.stone.utils.StringUtils;

import frm.ssh.action.BaseListAction;
import frm.ssh.util.SpringUtil;

public class GzrwdDbListAction extends BaseListAction {

	private static final long serialVersionUID = 3979577965804736350L;
	
	private ZbjlCommonService myService;
	
	public ZbjlCommonService getMyService() {
		return myService;
	}

	public void setMyService(ZbjlCommonService myService) {
		this.service = myService;
		this.myService = myService;
	}
	
    /** * 构造方法. */
    public GzrwdDbListAction() {
        this.entityClass = TGzrwdRw_old.class;
    }
	
	/**
	 * 设置查询条件
	 */
	/*public HashMap<String, Object> setSearchCondition() {
		
		HashMap<String, Object> m = new HashMap<String, Object>();
		
		List<Object> valsList = new ArrayList<Object>();
		
		// 登录者的organCode 100001
		String organCode = String.valueOf(super.getSession().getAttribute(IConstant.SESSION_TORGAN_CODE));
		// 是否管理员
		String isAdmin = (String) super.getSession().getAttribute(IConstant.SESSION_ISADMIN);
		
		String conditions = "";
		
		// 查询条件OUID很重要
		if ("1".equals(isAdmin)) {
			conditions = " AND OUID like '%," + organCode + "%,%'";
		}
		
		StringBuffer sql = new StringBuffer();
		
		// 异常故障处理任务（处理时间未填写）
		sql.append("SELECT YCNR AS GZRW,");
		sql.append(" '8' AS MODEL,");
		sql.append("ID AS ID");
		sql.append(" FROM TAB_YCGZ ");
		sql.append(" WHERE CLSJ IS NULL AND STATE = '0' ");
		sql.append(conditions);
		
		// 操作任务（倒闸操作记录操作结束时间）
		sql.append(" UNION ");
		sql.append("SELECT CZRW AS GZRW,");
		sql.append(" '6' AS MODEL,");
		sql.append("ID AS ID");
		sql.append(" FROM TAB_DZCZJL ");
		sql.append(" WHERE CZJSSJ IS NULL AND STATE = '0'");
		sql.append(conditions);
		
		// 许可任务（工作预告没有起草工作票记录）
		sql.append(" UNION ");
		sql.append("SELECT GZNR AS GZRW,");
		sql.append(" '2' AS MODEL,");
		sql.append("ID AS ID");
		sql.append(" FROM TAB_GZYG ");
		sql.append(" WHERE ID NOT IN (SELECT GZYGID FROM TAB_GZPTJJL WHERE GZYGID IS NOT NULL)");
		sql.append(conditions);
		
		// 正常巡视任务（巡视情况需要回写设置的巡视结束时间（比较时间 设置某个站多长时间巡视一次））
		sql.append(" UNION ");
		sql.append("　SELECT '巡视时间到期' AS GZRW,");
		sql.append(" '1' AS MODEL,");
		sql.append("　NULL AS ID");
		sql.append(" FROM SYS_ORGAN ");
		sql.append("  WHERE XCXSSJ IS NOT NULL and (TO_NUMBER(to_char(XCXSSJ,'YYYYMMDD')) + 3 ) ");
		sql.append(" >= TO_NUMBER(to_char(SYSDATE,'YYYYMMDD')) ");
		sql.append(" AND ORGAN_CODE like '" + organCode + "%'");
		
		// 上级工作安排记录
		sql.append(" UNION ");
		sql.append("　SELECT TZNR AS GZRW,");
		sql.append(" 'C' AS MODEL,");
		sql.append("　NULL AS ID");
		sql.append(" FROM TAB_SJZSQK ");
		sql.append("  WHERE WCSJ IS NOT NULL ");
		sql.append(conditions);
		
		m.put("pageflag", "sql");
		m.put("sql", sql.toString());
		
		// 查询条件
		m.put("conditions", "");
		m.put("vals", valsList.toArray());
			
		return m;
	}*/
    /**
	 * 设置查询条件
	 */
	public HashMap<String, Object> setSearchCondition() {
		
		HashMap<String, Object> m = new HashMap<String, Object>();
		
		List<Object> valsList = new ArrayList<Object>();
		
		m.put("cols", "new map(s.id as id, s.cjsj as cjsj, s.cjr as cjr, s.bdzname as bdzname, s.rwnr as rwnr)");
		
		// 条件
		String conditions = "  s.sfwc is null or s.sfwc='' "; 
		
		// 巡视开始时间
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon2())) {
			conditions += " AND TO_CHAR(s.kssj,'yyyy-MM-dd') >= ?";
			valsList.add(super.getSearchBean().getCon2());
		}
		
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon3())) {
			conditions += " AND TO_CHAR(s.jssj,'yyyy-MM-dd') <= ?";
			valsList.add(super.getSearchBean().getCon3());
		}
		
		// 变电站
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon4())) {
			conditions += " AND s.bdzname like ?";
			valsList.add("%" + super.getSearchBean().getCon4()+ "%");
		}
		
		// 巡视类型
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon7())) {
			conditions += " AND s.xslx = ?";
			valsList.add(super.getSearchBean().getCon7());
		}
		
		// 查询条件
		m.put("conditions",conditions);
		m.put("clause", " order by s.model,s.cjsj Desc");
		m.put("alias", " s");
		m.put("vals", valsList.toArray());
		
		return m;
		
	}
	
}
